package com.csnf.mall.controller;

import com.csnf.mall.entity.Category;
import com.csnf.mall.server.ICategoryServer;
import com.csnf.mall.server.imp.CategoryServerImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/product")
public class ProductController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ICategoryServer categoryServer = new CategoryServerImp(this);// 实例化 category 服务类
        List<Category> categories = categoryServer.getAllCategory();// 调用查询
        req.setCharacterEncoding("utf-8");// 编码设置为utf-8
        req.setAttribute("categories", categories);// 设置到 request 属性内
        req.getRequestDispatcher("/homepage.jsp").forward(req, resp);// 转发
    }
}
